package com.lanhu.designpattern.proxy.dynamic;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author 蓝狐
 */
public class OrderProxy implements IOrderService{
    private SimpleDateFormat format = new SimpleDateFormat("yyyy");
    private IOrderService orderService;


    public OrderProxy (IOrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 在这里同样实现了被代理类的接口，
     * 在调用被代理类之前做一些处理
     * @param order
     * @return
     */
    @Override
    public int createOrder (Order order) {
        Date createTime = order.getCreateTime();
        order.setOrderId(UUID.randomUUID().toString());
        int year = Integer.valueOf(format.format(createTime));
        DynamicDatasource.set(year);
        return this.orderService.createOrder(order);
    }
}
